//
//  LLColorButton.m
//  LLWalletSdk
//
//  Created by xuyf on 13-11-14.
//  Copyright (c) 2013年 LianLian. All rights reserved.
//

#import "LLColorButton.h"
#import "LLSmallUtil.h"

@interface LLColorButton()

@property (retain,nonatomic) UIView *grayView;

@end

@implementation LLColorButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.normalColor = [UIColor whiteColor];
        self.hilightColor = [UIColor blueColor];
        
        self.selectColor = [UIColor blueColor];
        self.selectHilightColor = [UIColor whiteColor];
        
        self.disableColor = [UIColor colorWithR:227 G:232 B:238 A:1];
        
        self.backgroundColor = self.normalColor;
        
        self.grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        self.grayView.backgroundColor = [UIColor lightGrayColor];
        self.grayView.hidden = YES;
        [self addSubview:self.grayView];
    }
    return self;
}


- (void)setHighlighted:(BOOL)highlighted
{
    [super setHighlighted:highlighted];
    if (highlighted) {
        
        if (self.selected) 
        {
//            self.backgroundColor = self.selectHilightColor;
        }
        else
        {
//            self.backgroundColor = self.hilightColor;
            self.grayView.frame = CGRectMake(0, 0, self.width, self.height);
            self.grayView.hidden = NO;
        }
    }
    else
    {
        [self redrawColor];
        self.grayView.hidden = YES;
    }
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    
    if (!self.enabled) {
        return;
    }
    
    [self redrawColor];
}

- (void)redrawColor
{
    if (!self.enabled) {
        self.backgroundColor = self.disableColor;
    }
    else if (self.selected)
    {
        self.backgroundColor = self.selectColor;
    }
    else
    {
        self.backgroundColor = self.normalColor;
    }
    
    self.grayView.backgroundColor = self.hilightColor;
}

- (void)setEnabled:(BOOL)enabled
{
    [super setEnabled:enabled];
    
    [self redrawColor];
}

@end